//
//  StatusCellTopView.swift
//  weibo
//
//  Created by Qing on 2017/7/26.
//  Copyright © 2017年 成哥哥. All rights reserved.
//

import UIKit

class StatusCellTopView: UIView {

    
    /// 视图模型
    var viewModel: StatusViewModel? {
        
        //设计工作
        didSet {
            //用户头像
            userIcom.sd_setImage(with: viewModel?.userProfileUrl, placeholderImage: viewModel?.userDefaultImage)
        
            //用户Vip等级图标
            userMbrankIcom.image = viewModel?.userMbankImage
            
            //官方认证图标
            verifiedTypeIcon.image = viewModel?.userVerifiedIcom

            //用户当前名字
            nameLable.text = viewModel?.status.user?.screen_name
            
            //微博发表时间
            created_at.text = "刚刚"//viewModel?.status.created_at
            
            //微博来源
            sourceLable.text = "青青微博"//viewModel?.status.source
        
        }
    }

    
    
//    MARK: - 初始化
    override init(frame: CGRect) {

        super.init(frame: frame)
        

        setUI()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

// MARK: - 懒加载控件
    /// 用户头像
     lazy var userIcom: UIImageView = UIImageView(image: #imageLiteral(resourceName: "userIcom"))
    
    /// 用户昵称
     lazy var nameLable: UILabel = UILabel(texts: "老王", fontSize: 12)
    
    /// 用户Vip等级图标
     lazy var userMbrankIcom: UIImageView = UIImageView(image: UIImage(named: "avatar_1"))
    
    /// 认证图标
     lazy var verifiedTypeIcon: UIImageView = UIImageView(image: UIImage(named: "avatarType"))
    
    //TODO: - 后续会更改
    /// 微博创建时间
     lazy var created_at: UILabel = UILabel(texts: "刚刚", Color: UIColor.orange, fontSize: 10)
    
    /// 来源
     lazy var sourceLable: UILabel = UILabel(texts: "天天", Color: UIColor.orange, fontSize: 10)
}


// MARK: - 界面设置
extension StatusCellTopView {
    
    
    /// 加载UI
    fileprivate func setUI() {
        
        /// Cell上面的分割线
        let v = UIView()
        v.backgroundColor = UIColor(white: 0.85, alpha: 1)
        
        
//        backgroundColor = UIColor(white: 0.95, alpha: 1)
//        1.加载控件
        addSubview(userIcom)
        addSubview(nameLable)
        addSubview(userMbrankIcom)
        addSubview(created_at)
        addSubview(sourceLable)
        addSubview(verifiedTypeIcon)
        addSubview(v)
        
//        2.自动布局
//        1>用户头像
        userIcom.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top).offset(2 * StatusCellMargin)
            make.left.equalTo(self.snp.left).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
//        2>用户昵称
        nameLable.snp.makeConstraints { (make) in
            make.top.equalTo(userIcom.snp.top)
            make.left.equalTo(userIcom.snp.right).offset(StatusCellMargin)
//            make.right.equalTo(10)
//            make.height.equalTo(10)
        }
//        3> 用户Vip等级
        userMbrankIcom.snp.makeConstraints { (make) in
            make.top.equalTo(nameLable.snp.top)
            make.left.equalTo(nameLable.snp.right).offset(StatusCellMargin)
            make.width.equalTo(StatusCellVerifiedIcom)
            make.height.equalTo(StatusCellVerifiedIcom)
        }
//        4> 创建时间
        created_at.snp.makeConstraints { (make) in
            make.top.equalTo(nameLable.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(nameLable.snp.left)
        }
        
//        5>来源
        sourceLable.snp.makeConstraints { (make) in
            make.top.equalTo(created_at.snp.top)
            make.left.equalTo(created_at.snp.right).offset(StatusCellMargin)
        }
//        6>认证图标
        verifiedTypeIcon.snp.makeConstraints { (make) in
            make.bottom.equalTo(userIcom.snp.bottom)
            make.right.equalTo(userIcom.snp.right)
            make.width.equalTo(StatusCellVerifiedIcom)
            make.height.equalTo(StatusCellVerifiedIcom)
        }
//        7> Cell顶部的分割线
        v.snp.makeConstraints { (make) in
            make.bottom.equalTo(userIcom.snp.top).offset(-StatusCellMargin)
            make.width.equalTo(self.snp.width)
            make.left.equalTo(self.snp.left)
            make.height.equalTo(StatusCellMargin)
        }
    }

}
